<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="审核单编号">
              <j-input placeholder="请输入审核单编号" v-model="queryParam.billNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="结算年度">
              <!-- 这里的list接口查询是查询在职员工档案中的已维护岗位的公司 -->
              <a-select  placeholder="请选择年度" v-model="queryParam.settlementYear">
                <a-select-option  v-for="(province) in yearData1" :key="province">
                  {{ province }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="结算月度">
              <a-select placeholder="请选择月度" v-model="queryParam.settlementMonth">
                <a-select-option v-for="(item) in monthData2" :key="item">
                  {{ item }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <j-input placeholder="请输入项目名称" v-model="queryParam.projectName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="经营团队" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <select-team-input placeholder="请选择经营团队" v-model="queryParam.operateTeamId" :tdlx="1"  :teamType="0"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="生产团队">
              <select-team-input v-model="queryParam.productTeam" :tdlx="1" :teamType="0" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="业绩归属年度" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-model="queryParam.attributionYear" dictCode="yjgsnd" placeholder="请选择业绩归属年度" />
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="审核人">
              <select-user-by-dep  placeholder="请选择审核人" :multi="false" v-model="queryParam.auditEmpId" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="项目承接人" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <select-user-by-dep :multi="false" v-model="queryParam.undertaker"></select-user-by-dep>
          </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="项目负责人" :labelCol="labelCol" :wrapperCol="wrapperCol">
            <select-user-by-dep :multi="false" v-model="queryParam.projectLeading"></select-user-by-dep>
          </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="任务类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag
                type="list"
                v-model="queryParam.taskType"
                dictCode="task_type"
                placeholder="请选择任务类型"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="结算状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag
                type="list"
                v-model="queryParam.settlementStatus"
                dictCode="settlement_status"
                placeholder="请选择结算状态"/>
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button :loading="exportLoading" type="primary" icon="download" @click="handleExportXls('审核费统计表')"
                :disabled="isDisabledAuth('erpOmcProject:export')">导出
      </a-button>
      <!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
              <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpOmcProject:import')">导入</a-button>
            </a-upload>-->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <!--      <a-dropdown v-if="selectedRowKeys.length > 0">
              <a-menu slot="overlay">
                <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpOmcProject:delete')"><a-icon type="delete"/>删除</a-menu-item>
              </a-menu>
              <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
            </a-dropdown>-->
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item, index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right; margin-top: -20px;">
          <a-icon type="setting" :style="iconStyle"/>
        </a>
      </a-popover>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        bordered
        :components="draggableComponent"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <template slot="action" slot-scope="text, record">
          <span>
            <a-button
              type="primary"
              size="small"
              :disabled="record.billStatus === 'Invalid' || record.billStatus === 'invalid_in_progress'"
              @click="settlements(record)">结算</a-button>
            </span>
        </template>
      </a-table>
    </div>
    <a-modal v-model="Gvisible" :width="600" title="结算" @cancel="clickGvisible">
        <a-form-model ref="forms" :model="formData" :rules="validatorRules" >
          <a-row :gutter="48">
            <a-col :span="24">
              <a-form-model-item label="结算年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="settlementYear">
                <a-select placeholder="请选择年度" v-model="formData.settlementYear" style="width: 300px">
                    <a-select-option  v-for="(province) in yearData" :key="province">
                      {{ province }}
                    </a-select-option>
              </a-select>
            </a-form-model-item>

            </a-col>
            <a-col :span="24">
              <a-form-model-item label="结算月度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="settlementMonth">
                <a-select placeholder="请选择月度" v-model="formData.settlementMonth" style="width: 300px">
                    <a-select-option v-for="(item) in monthData" :key="item">
                      {{ item }}
                    </a-select-option>
              </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
        <template slot="footer">
          <a-button @click="clickGvisible">取消</a-button>
          <a-button type="primary" @click="confirm">确认</a-button>
        </template>
      </a-modal>
  </a-card>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import Area from '@/components/_util/Area'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectTeamInput from '@views/scy/components/SelectTeamInput'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectCustomerInput from '@views/scy/components/SelectCustomerInput'
import BusinessCategoryNameSelect from '@views/erp/components/BusinessCategoryNameSelect'
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import { httpAction, deleteAction } from '@/api/manage'
import { getAction } from '@/api/manage'
export default {
  name: 'ErpauditFeeStatistics',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    SelectTeamInput,
    SelectUserByDep,
    SelectCustomerInput,
    BusinessCategoryNameSelect,
    SelectCompanyInput
  },
  data() {
    return {
      /* 排序参数 */
      isorter: {
        column: 'createTime',
        order: 'desc'
      },
      forms:null,
      description: '立项档案信息管理页面',
      //表头
      columns: [],
      yearData:['2018','2019','2020','2021','2022','2023','2024','2025','2026','2027','2028','2029','2030'],
      monthData:['01','02','03','04','05','06','07','08','09','10','11','12'],
      yearData1:['2018','2019','2020','2021','2022','2023','2024','2025','2026','2027','2028','2029','2030'],
      monthData2:['01','02','03','04','05','06','07','08','09','10','11','12'],
      id:'',
      Gvisible:false,
      //列设置
      settingColumns: [],
      formData:{
        settlementYear:'',
        settlementMonth:''
      },
      validatorRules: {
        settlementYear: [
          { required: true, message: '请选择结算年度!' },
        ],
        settlementMonth: [
          { required: true, message: '请选择结算月份!' },
        ],
      },
      // 列定义
      defColumns:[
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          ellipsis: true,
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '结算状态',
          align: 'center',
          width: 100,
          ellipsis: true,
          dataIndex: 'settlementStatus_dictText',
    
        },
        {
          title: '结算年度',
          align: 'center',
          width: 100,
          ellipsis: true,
          dataIndex: 'settlementYear',
        },
        {
          title: ' 结算月份',
          align: 'center',
          width: 100,
          ellipsis: true,
          dataIndex: 'settlementMonth'
        },
        {
          title: '审核单编号',
          align: 'center',
          width: 240,
          ellipsis: true,
          dataIndex: 'billNo'
        },
        {
          title: '报告类型',
          align: 'center',
          width: 80,
          ellipsis: true,
          dataIndex: 'reportType_dictText'
        },
        {
          title: '出资单位',
          align: 'center',
          width: 230,
          ellipsis: true,
          dataIndex: 'qualificationUnit_dictText'
        },
        {
          title: '项目名称',
          align: 'center',
          width: 160,
          ellipsis: true,
          dataIndex: 'projectName'
        },
        {
          title: '任务类型',
          align: 'center',
          width: 160,
          ellipsis: true,
          dataIndex: 'taskType_dictText'
        },
        {
          title: '任务最终成果报告名称(全称)',
          align: 'center',
          width: 220,
          ellipsis: true,
          dataIndex: 'projectResult'
        },
        {
          title: '业绩归属年度',
          align: 'center',
          width: 160,
          ellipsis: true,
          dataIndex: 'attributionYear'
        },
        {
          title: '项目承接人',
          align: 'center',
          width: 160,
          ellipsis: true,
          dataIndex: 'undertaker_dictText'
        },
        {
          title: '经营团队',
          align: 'center',
          width: 200,
          ellipsis: true,
          dataIndex: 'operateTeamId_dictText'
        },
        {
          title: '生产团队',
          align: 'center',
          width: 200,
          ellipsis: true,
          dataIndex: 'productTeam_dictText'
        },
        {
          title: '项目负责人',
          align: 'center',
          width: 100,
          ellipsis: true,
          dataIndex: 'projectLeading_dictText'
        },
        {
          title: '审核人',
          align: 'center',
          width: 100,
          ellipsis: true,
          dataIndex: 'auditEmpId_dictText'
        },
        {
          title: '审核人工号',
          align: 'center',
          width: 100,
          ellipsis: true,
          dataIndex: 'auditEmpNo'
        },
        {
          title: '审核角色',
          align: 'center',
          width: 120,
          ellipsis: true,
          dataIndex: 'userType_dictText'
        },
        {
          title: '预计审核费(元)',
          align: 'center',
          width: 150,
          ellipsis: true,
          dataIndex: 'expectedAuditFee'
        },
        {
          title: '扣除比例',
          align: 'center',
          width: 100,
          ellipsis: true,
          dataIndex: 'deductionRatio_dictText'
        },
        {
          title: '实际审核费(元)',
          align: 'center',
          width: 150,
          ellipsis: true,
          dataIndex: 'actualAuditFee'
        },
        {
          title: '签字费(元)',
          align: 'center',
          width: 100,
          ellipsis: true,
          dataIndex: 'signatureFee'
        },
        {
          title: '是否跨团队审核',
          align: 'center',
          width: 150,
          ellipsis: true,
          dataIndex: 'crossTeamReview_dictText'
        },
        {
          title: '作废状态',
          align: 'center',
          width: 100,
          ellipsis: true,
          dataIndex: 'billStatus_dictText'
        },
        {
          title: '操作',
          align: 'center',
          width: 100,
          ellipsis: true,
          dataIndex: 'action',
          scopedSlots: {
          customRender: 'action'
        }
        },
      ],
      url: {
        list: '/api/erp/omc/reportaudit/erpReportAuditStatistics/list',
        delete: '/api/erp/omc/project/erpOmcProject/delete',
        deleteBatch: '/api/erp/omc/project/erpOmcProject/deleteBatch',
        exportXlsUrl: '/api/erp/omc/reportaudit/erpReportAuditStatistics/exportXls',
        importExcelUrl: 'api/erp/omc/project/erpOmcProject/importExcel',
        // 结算
        settlement: '/api/erp/omc/reportaudit/erpReportAuditStatistics/settlement',
        query: '/api/erp/omc/reportaudit/erpReportAuditStatistics/queryById',
      },
      dictOptions: {},
      pcaData: '',
      superFieldList: [],
    }
  },
  created() {
    this.pcaData = new Area()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {

    clickGvisible(){
      this.Gvisible = false
      this.$refs.forms.resetFields()
    },

  async confirm(){
    
    this.$refs.forms.validate(async valid=>{
      if(!valid)return 
      let params = {
        id:this.id,
        ...this.formData,
        settlementStatus:'already'
      }
      const res = await httpAction(this.url.settlement,params,'put')
      this.Gvisible = false
      this.$message.success('编辑成功')
      this.loadData()
    })
    },
    getPcaText(code) {
      return this.pcaData.getText(code);
    },
    initDictConfig() {},
    async settlements(record){
      this.Gvisible = true
      this.id = record.id
      const res = await  getAction(this.url.query,{id:record.id})
      this.formData.settlementYear = res.result.settlementYear
      this.formData.settlementMonth = res.result.settlementMonth
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'year', text: '归属年度', dictCode: 'yjgsnd' })
      fieldList.push({ type: 'string', value: 'accountAdmin', text: '台账管理员', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectAddress', text: '项目地址', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'outline', text: '项目内容概要', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'prepareProjectId',
        text: '预立项',
        dictCode: 'erp_omc_prepare_project,mc,id'
      })
      fieldList.push({ type: 'string', value: 'projectName', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectNo', text: '项目编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectType', text: '项目类型', dictCode: 'xmlx_type' })
      fieldList.push({ type: 'string', value: 'ownerUnit', text: '业主单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handler', text: '经办人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handingDepartmernt', text: '经办部门', dictCode: 'departments' })
      fieldList.push({ type: 'string', value: 'teamName', text: '经营团队', dictCode: 'teams' })
      fieldList.push({ type: 'string', value: 'undertaker', text: '承接人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'projectEstablishDate', text: '立项日期' })
      fieldList.push({ type: 'string', value: 'signUnit', text: '签订单位', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'estimatedContractAmount', text: '预计合同额(元)', dictCode: '' })
      fieldList.push({ type: 'string', value: 'estimatedContractcapitalChineseAmount', text: '预计合同额(元)大写', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'isEnvironmentalAssessmentProject',
        text: '是否环评项目',
        dictCode: 'YES_OR_NO'
      })
      fieldList.push({ type: 'string', value: 'contacts', text: '联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'contactTel', text: '联系方式', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectSource', text: '项目来源', dictCode: 'xmly_type' })
      fieldList.push({ type: 'string', value: 'isPrepareEstablish', text: '数据来源', dictCode: 'omc_project_type' })
      fieldList.push({ type: 'string', value: 'status', text: '流程状态', dictCode: 'project_status' })
      fieldList.push({ type: 'string', value: 'attachment', text: '相关附件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'isPrepareEstablish', text: '是否预立项', dictCode: 'YES_OR_NO' })
      fieldList.push({ type: 'string', value: 'isBidding', text: '是否招投标', dictCode: 'YES_OR_NO' })
      fieldList.push({ type: 'Text', value: 'establishReason', text: '立项事由及说明', dictCode: '' })
      fieldList.push({ type: 'pca', value: 'areaCode', text: '县区编码' })
      this.superFieldList = fieldList
    },
    businessCategoryHandle(obj) {
      if (obj) {
        this.queryParam.businessCategory = obj.categoryCode;
      }
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
